package com.ygxsk.carhome.ui.adapter;

import android.text.TextUtils;
import android.widget.ImageView;

import androidx.annotation.Nullable;

import com.blankj.utilcode.util.StringUtils;
import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.tencent.mmkv.MMKV;
import com.ygxsk.carhome.R;
import com.ygxsk.carhome.constant.ConstantSign;
import com.ygxsk.carhome.response.ShopCartBean;
import com.ygxsk.carhome.utils.CommUtils;

import java.math.BigDecimal;
import java.util.List;

/**
 * Created by itchenqi on 2018/3/19 0019.
 * description：商品订单内部的小
 */
public class OrderInsideAdapter extends BaseQuickAdapter<ShopCartBean, BaseViewHolder> {

    public OrderInsideAdapter(int layoutResId, @Nullable List<ShopCartBean> data) {
        super(layoutResId, data);
        //mSession = Session.get(mContext);
    }

    @Override
    protected void convert(BaseViewHolder helper, ShopCartBean item) {

        if (item != null) {

            String imageUrl = item.getLogoImg();
            String titleName = item.getProductFullName();

            String info = item.getSpecification();//简介短信息
            int countInShopCart = item.getProductCount();//商品购物车内的购买数量

            //ImageView imageviewinaccount = (ImageView) helper.getView(R.id.imageviewinside);

            helper.setText(R.id.textvewititlenameinside, TextUtils.isEmpty(titleName) ? "" : titleName);

            //若 isVipOrder =1;是会员商品 那末不显示商品价格和下边的总价格
            //若 isVipOrder =0;不是会员商品，时普通商品， 那末需要展示商品价格和下边的总价格

            if (item.getIsVipOrderSon() == 0) {

                //原始代码
                BigDecimal price = item.getSalesPrice();
                //String yangJiao = mSession.getCurrencySymbol();
                //String salePriceFinal = yangJiao + CommUtils.formatComma2BigDecimal(price);

                String salePriceFinal = "";
                if (price != null) {
                    salePriceFinal = MMKV.defaultMMKV().decodeString(ConstantSign.P_CURRENCYSYMBOL, StringUtils.getString(R.string.yangjiaocurrencysymbol)) + CommUtils.formatComma2BigDecimal(price);
                } else {
                    salePriceFinal = MMKV.defaultMMKV().decodeString(ConstantSign.P_CURRENCYSYMBOL, StringUtils.getString(R.string.yangjiaocurrencysymbol)) + CommUtils.formatComma2BigDecimal(CommUtils.valueOf(0.00));
                }

                helper.setText(R.id.textviewshoppriceinside, TextUtils.isEmpty(salePriceFinal) ? "" : salePriceFinal);


            } else if (item.getIsVipOrderSon() == 1) {

                //是会员产品 不展示价格
                helper.setText(R.id.textviewshoppriceinside, "");

            }

            helper.setText(R.id.textviewinfojieinside, TextUtils.isEmpty(info) ? "" : info);
            helper.setText(R.id.textviewcountrightinside, "x" + (TextUtils.isEmpty(String.valueOf(countInShopCart)) ? "0" : String.valueOf(countInShopCart)));

            Glide.with(getContext())//
                    .load(imageUrl.trim())//
                    //.transition(withCrossFade())
                    .placeholder(R.drawable.icon_errorfang)//
                    .error(R.drawable.icon_errorfang)//
                    .fallback(R.drawable.icon_errorfang)//
                    .into((ImageView) helper.getView(R.id.imageviewinside));//

        }
    }
}
